var e_dealurl_param = ['e_app', 'e_wz'];

function ChangeParam(url, name, value) {
	if (url == '') return '';
	var newUrl = "";
	var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)");
	var tmp = name + "=" + value;
	if (url.match(reg) != null) {
		newUrl = url.replace(eval(reg), tmp);
	} else {
		if (url.match("[\?]")) {
			newUrl = url + "&" + tmp;
		} else {
			newUrl = url + "?" + tmp;
		}
	}

	return newUrl;
}

function getParam(name) {
	return location.href.match(new RegExp('[?&]' + name + '=([^?&#]+)', 'i')) ? decodeURIComponent(RegExp.$1) : '';
}

function e_dealurl(url, par) {
	if (par == '_tuitan' && getParam('_share')) {
		return url;
	}

	if (par) {
		url = ChangeParam(url, par, 1);
	}

	if (e_dealurl_param.length > 0) {
		for (var i = 0; i <= e_dealurl_param.length - 1; i++) {
			var pk = e_dealurl_param[i];
			if (getParam(pk)) {
				url = ChangeParam(url, pk, getParam(pk));
			}
		}
	}

	return url;
}

function norefjump(url) {
	var len = 10;
	var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz';
	var maxPos = $chars.length;
	var pwd = '';
	for (i = 0; i < len; i++) {
		pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
	}

	var newV = document.createElement("a");
	newV.setAttribute("id", pwd);
	newV.setAttribute("href", url);
	newV.setAttribute("rel", 'noreferrer');

	document.body.appendChild(newV);
	document.getElementById(pwd).click();
}

function tj_api_play() {
	var e_app = getParam('e_app')
	if (e_app != '' && !getParam('_share')) {
		var url = 'http://cnpijiang.com/stat/share?e=' + e_app;
		$.ajax({
			url: url,
			type: "GET",
			dataType: "jsonp",
			success: function(data) {

			}
		});
	}
}

function tj_api_share(time) {
	var e_app = getParam('e_app')
	if (e_app != '' && !getParam('_share')) {
		var url = 'http://cnpijiang.com/stat/share_success?e=' + e_app + '&share_times=' + time;
		$.ajax({
			url: url,
			type: "GET",
			dataType: "jsonp",
			success: function(data) {

			}
		});
	}

	var e_wz = getParam('e_wz')
	if (e_wz != '' && !getParam('_share')) {
		var url = 'http://51cms.net/wzshare.php?e=' + e_wz + '&share_count=' + time;
		$.ajax({
			url: url,
			type: "GET",
			dataType: "jsonp",
			success: function(data) {

			}
		});
	}
}